s = {10, 20, 30, 40}
print(s)

# 元组集合
s = {(10, 20, 30), (40, 50, 60), (70, 80, 90)}
print(s)

s = {}
print(type(s))

# 创建空集合
s = set()
print(s, type(s))

# 创建非空集合，重复元素会被自动过滤
s = set('helloworld')
print(s)

s = set(range(6))
print(s, max(s), min(s), len(s), (2 in s), (2 not in s))

# 集合的删除
s = {10, 20, 30, 40}
s.remove(10)
print(s)

# 清空集合
s.clear()
print(s)

# 集合的运算
s1 = {10, 20, 30, 40}
s2 = {20, 30, 40, 50, 60}

# 集合的交集
print(s1 & s2)
# 集合的并集
print(s1 | s2)
# 集合的差集
print(s1 - s2)
print(s2 - s1)
# 集合的对称差集(在s1或s2中，但不会同时出现在二者中，也叫补集)
print(s1 ^ s2)

# 集合的比较运算
s1 = {10, 20, 30}
s2 = {10, 20, 30, 40}
s3 = {10, 20, 50}
s3.add(30)
print(s1 < s2)

# 集合的遍历
s = {10, 20, 30, 40}
for i in s:
    print(i)

# 使用 enumerate() 函数处理集合
s = {10, 20, 30, 40}
for index, i in enumerate(s, 10):
    print(index, i)

# 生成式
s = {i for i in range(10)}
print(s)
